package com.Servlet;

import javax.servlet.AsyncContext;
import javax.servlet.ServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Date;

/**
 * @auther: cc.ly
 * @date: 2019/1/22/022
 */

public class WorkProcessor implements Runnable {

    private AsyncContext asyncContext;

    public WorkProcessor(AsyncContext asyncContext) {
        this.asyncContext = asyncContext;
    }

    @Override
    public void run() {
        try {
            ServletResponse response = asyncContext.getResponse();
            PrintWriter writer = response.getWriter();
            writer.println("servlet async start:" + new Date() + "  " + Thread.currentThread().getName());
            Thread.sleep(2000);
            writer.println("servlet async end:" + new Date() + "  " + Thread.currentThread().getName());
            asyncContext.complete();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
